# coding=utf-8
from appium.webdriver.common.mobileby import MobileBy
from Base.basepage import BasePage
from common.LoggerUtil import LogUtils


class Daily_Clock_Page(BasePage):

    loc_image_sign = (MobileBy.ID, "com.youth.startup:id/image_sign") # 点击首页早起打卡
    loc_widgetToast = (MobileBy.XPATH, "/hierarchy/android.widget.Toast") # 获取早起打卡信息
    loc_line3 = (MobileBy.ID, "com.youth.startup:id/text_line3") # 取消分享
    loc_number = (MobileBy.ID, "com.youth.startup:id/text_head_number")  # 打卡天数
    loc_back = (MobileBy.ID, "com.youth.startup:id/image_back")  # 返回
    loc_image_share = (MobileBy.ID, "com.youth.startup:id/image_share") # 分享
    loc_line_friend = (MobileBy.ID, "com.youth.startup:id/line_friend") # 微信好友
    loc_d7d = (MobileBy.ID, "com.tencent.mm:id/d7d") # 微信搜索

    def daily_clock_page(self):

        try:
            self.locator(self.loc_image_sign).click()
            res = self.get_toast(self.loc_widgetToast).text
            self.take_screenshot("【早起打卡】截图_")
            if res == '打卡成功，奖励+5积分':
                LogUtils.info('----早起打卡：%s----', res)
                self.locator(self.loc_line3).click()
            elif res == '今日已签到':
                LogUtils.info('----早起打卡：%s----', res)
            elif res == '请在每日 04:00~06:31 期间打卡':
                LogUtils.info('----早起打卡：%s----', res)
            else:
                return "早起打卡异常！"
            text_number = self.locator(self.loc_number).text
            LogUtils.info('----早起打卡天数：%s----',text_number)
            self.locator(self.loc_back).click()
        except Exception as e:
            LogUtils.error(f'早起打卡异常：{e}-----')
            self.take_screenshot("【早起打卡异常】截图_")

